package org.harsh.transmission.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.harsh.transmission.domain.TransSubtask;
import org.harsh.transmission.service.ITransSubtaskService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 子传输任务Controller
 * 
 * @author liuhaibo
 * @date 2024-08-25
 */
@Controller
@RequestMapping("/transmission/subtask")
public class TransSubtaskController extends BaseController
{
    private String prefix = "transmission/subtask";

    @Autowired
    private ITransSubtaskService transSubtaskService;

    @RequiresPermissions("transmission:subtask:view")
    @GetMapping()
    public String subtask()
    {
        return prefix + "/subtask";
    }

    /**
     * 查询子传输任务列表
     */
    @RequiresPermissions("transmission:subtask:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransSubtask transSubtask)
    {
        startPage();
        List<TransSubtask> list = transSubtaskService.selectTransSubtaskList(transSubtask);
        return getDataTable(list);
    }

    /**
     * 导出子传输任务列表
     */
    @RequiresPermissions("transmission:subtask:export")
    @Log(title = "子传输任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransSubtask transSubtask)
    {
        List<TransSubtask> list = transSubtaskService.selectTransSubtaskList(transSubtask);
        ExcelUtil<TransSubtask> util = new ExcelUtil<TransSubtask>(TransSubtask.class);
        return util.exportExcel(list, "子传输任务数据");
    }

    /**
     * 新增子传输任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存子传输任务
     */
    @RequiresPermissions("transmission:subtask:add")
    @Log(title = "子传输任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransSubtask transSubtask)
    {
        return toAjax(transSubtaskService.insertTransSubtask(transSubtask));
    }

    /**
     * 修改子传输任务
     */
    @RequiresPermissions("transmission:subtask:edit")
    @GetMapping("/edit/{subTaskId}")
    public String edit(@PathVariable("subTaskId") Long subTaskId, ModelMap mmap)
    {
        TransSubtask transSubtask = transSubtaskService.selectTransSubtaskBySubTaskId(subTaskId);
        mmap.put("transSubtask", transSubtask);
        return prefix + "/edit";
    }

    /**
     * 修改保存子传输任务
     */
    @RequiresPermissions("transmission:subtask:edit")
    @Log(title = "子传输任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransSubtask transSubtask)
    {
        return toAjax(transSubtaskService.updateTransSubtask(transSubtask));
    }

    /**
     * 删除子传输任务
     */
    @RequiresPermissions("transmission:subtask:remove")
    @Log(title = "子传输任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transSubtaskService.deleteTransSubtaskBySubTaskIds(ids));
    }
}
